package com.eight.cloud.openfeign.message.model;

import cn.hutool.core.util.ObjectUtil;
import com.eight.cloud.openfeign.message.enums.BindingNameEnum;
import com.eight.cloud.openfeign.message.enums.RoutingKeyEnum;
import com.eight.cloud.rabbitmq.util.SendStrategy;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * rabbitMq消息实体
 *
 * @ClassName: MqMessage
 * @Author: TXC
 * @Date: 2025-08-15 10:00
 **/
@Data
public class MqMessage<T> implements Serializable {
    /**
     * 绑定目标名称
     */
    @NotNull(message = "绑定目标名称不能为空")
    private BindingNameEnum bindingName;
    /**
     * 路由键
     */
    @NotNull(message = "路由键不能为空")
    private RoutingKeyEnum routingKey;
    /**
     * 消息内容
     */
    @NotNull(message = "消息内容不能为空")
    private T payload;

    /**
     * 发送策略
     */
    private SendStrategy sendStrategy;

    public String getBindingName() {
        return bindingName.getValue();
    }

    public String getRoutingKey() {
        return routingKey.getValue();
    }

    public SendStrategy getSendStrategy() {
        return ObjectUtil.defaultIfNull(sendStrategy, SendStrategy.defaultStrategy());
    }
}
